-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set up API client code generation #121
Conversation
b93ab79
to
57e785c
Compare
57e785c
to
265c7fa
Compare
if result.returncode != 0: | ||
logging.error("ktlint failed, but continuing with the rest of the script.") | ||
|
||
target_line = "import com.tidal.sdk.tidalapi.generated.infrastructure.CollectionFormats.*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that ktlint
cannot fix these imports (* imports of types provided by us), so after it is run, we manually remove them anywhere they show up as we don't need them, but openapi-generator
just puts it everywhere
|
||
], | ||
"output": "./tidal-api-joined.json", | ||
"openapi_generator_path": "tbd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would point to where the executable would be found. As I still work on providing it, it is tbd for now (which means, if you run the python script, it will download and merge the API schemas, but won't (re-) generate the code).
f"No lines starting with '{target_string}' found in file: {file_path}") | ||
|
||
|
||
def merge_openapi_schemas(file_paths, output_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was it required for you? Would a simpler approach (just process all files one by one and overwrite models) like we did on iOS not work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I answered this already, but the answer got lost.
In short: I generate interfaces for each place a oneOf item is used - and those places are distributed across all APIS. So if I generate them consecutively, each generation overwrites code I just created. That's why the generator needs full context before run.
tidalapi/src/main/kotlin/com/tidal/sdk/tidalapi/networking/AuthInterceptor.kt
Show resolved
Hide resolved
tidalapi/src/main/kotlin/com/tidal/sdk/tidalapi/networking/DefaultAuthenticator.kt
Show resolved
Hide resolved
I don't see why we would want to commit the generated code. It sounds more reasonable to me to generate it on CI on publish, put it in the published binary and that's it. |
There are a number of reasons for it, here are some:
I know that you added a similar comment on my earlier PR, and I would have liked to do it that way too. I did a good amount of work towards that goal. But this approach made the most sense to thew devs involved (not just for Android) and so we decided to go with this way. However, once we are past an MVP situation and both schema design and client use have stabilized it might be nice to revisit the approach and maybe reconsider/improve, but currently this is the way to go. |
This adds a python script that does the following: 1. Download the schemas 2. Join the schemas (assuming all entries with the same name are equal, which we discussed they should be. This works as intended now). 3. Run openapi-generator-cli from a specified location (since we will have to submit our own fork). Also added are the config yaml for the generator and the custom template for our ApiClient.
…yze mustache files The pattern matching would catch .kt.mustache before, now it doesn't anymore.
openapi-generator has a poat-processiong option, but since we're using a dedicated script to run ktlint, I decided to add the step for this here. With this change, ktlint will try and autoformat as many violations as possible. While not all of them get fixed, especially cleaning up imports is quite useful, as the generator creates a lot of unnecessary import statements.
This approach is taken from this tool: https://www.npmjs.com/package/openapi-merge-cli The tool itself didn't work out, but I like the approach over command line args, especially if its - like here - a number of long urls.
This ensures that in case of changed names/removals we don't end up with dead types that won't get removed.
6d2c046
to
9573a62
Compare
This PR adds the main code generation setup to
:tidalapi
, as well as the generated files.Please review commit by commit to have an easy overview, and just skip the commit adding the generated files 😄
Note for reviewers:
The code in this pull request is a MVP. Please point out anything you don't like, but the idea is to get this one merged and then improve what needs improving in subsequent PRs. So if you request changes it should be for things that absolutely can't go in like this.
Please also look at the additional info provided in the commit messages.
Note about the generated code:
I debated whether it should be in the
src
folder or not, but after some reading I decided yes, because:How can you test this?
MavenLocal
MavenLocal
insettings.gradle.kts
like this:com.tidal.sdk.tidalapi:0.1.0
where you want to use it, and instantiate an api client like this:Do you need to test it to review this?
At this stage, no imho. But if you like to, feel free!
How to/ test code generation?
As you currently need a binary of my fork of
openapi-generator
, ask me personally, if you want to play around with it.But after this PR, we wil quickly move towards making this available via GH Actions, which will simplify this all.